package com.xiaoluo.drawable;

import androidx.annotation.ColorInt;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.Log;
import android.widget.ImageView;

public class MainActivity extends AppCompatActivity {
    private static final String TAG = "MainActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        DisplayMetrics dm = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(dm);
        Log.i(TAG, "dpi :" + dm.densityDpi);

        Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_test_h);
        Log.i(TAG, "bitmap size is :" + bitmap.getAllocationByteCount());

        ImageView imageView = findViewById(R.id.imageView);
        //imageView.setImageResource(R.drawable.a);
        imageView.setBackground(getDrawable(Color.parseColor("#1affffff"),Color.parseColor("#ffffff"),5));
    }

    public static GradientDrawable getDrawable(@ColorInt int Color, int strokeColor, int strokeWidth) {
        GradientDrawable gradientDrawable = new GradientDrawable();
        gradientDrawable.setColor(Color);
        gradientDrawable.setStroke(strokeWidth, strokeColor);
     //   gradientDrawable.setCornerRadii(radius);
        return gradientDrawable;
    }

}
